package tankGame04.tank;


/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-03-08
 * Time:15:30
 */
@SuppressWarnings("all")
public class Bullet implements Runnable {
    private int x;
    private int y;
    public static final int BULLET_WIDTH = 2;
    public static final int BULLET_LENGTH = 5;
    private int direct;//0-UP 1-RIGHT 2-DOWN 3-LEFT
    private final int speed = 10;

    public Bullet(int x, int y, int direct, boolean state) {
        this.x = x;
        this.y = y;
        this.direct = direct;
        this.state = state;
    }

    private boolean state = false;

    public Bullet(int x, int y, int direct) {
        this.x = x;
        this.y = y;
        this.direct = direct;
    }

    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            switch (direct) {
                case 0:
                    y -= speed;
                    break;
                case 1:
                    x += speed;
                    break;
                case 2:
                    y += speed;
                    break;
                case 3:
                    x -= speed;
                    break;
            }
            if (!(x > 0 && x < 1000 && y > 0 && y < 750)) {
                state = false;
                break;
            }
        }
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public boolean isState() {
        return state;
    }

    public int getDirect() {
        return direct;
    }

    public void setState(boolean state) {
        this.state = state;
    }
}
